package com.example.meet.fragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.framework.adapter.CloudTagAdapter;
import com.example.framework.base.BaseFragment;
import com.example.framework.utils.LogUtils;
import com.example.meet.R;
import com.example.meet.ui.AddFriendActivity;
import com.moxun.tagcloudlib.view.TagCloudView;

import java.util.ArrayList;
import java.util.List;

public class MeetFragment extends BaseFragment implements View.OnClickListener{
    private ImageView iv_camera;
    private ImageView iv_add;
    private TagCloudView mCloudView;

    private LinearLayout ll_random;
    private TextView tv_random;
    private LinearLayout ll_soul;
    private TextView tv_soul;
    private LinearLayout ll_fate;
    private TextView tv_fate;
    private LinearLayout ll_love;
    private TextView tv_love;

    private CloudTagAdapter mTagAdapter;
    private List<String> mData = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_meet, null);
        initView(view);
        return view;
    }

    private void initView(View view) {
        iv_camera = view.findViewById(R.id.iv_camera);
        iv_add = view.findViewById(R.id.iv_add);

        mCloudView = view.findViewById(R.id.mCloudView);

        ll_random = view.findViewById(R.id.ll_random);
        ll_soul = view.findViewById(R.id.ll_soul);
        ll_fate = view.findViewById(R.id.ll_fate);
        ll_love = view.findViewById(R.id.ll_love);

        iv_camera.setOnClickListener(this);
        iv_add.setOnClickListener(this);
        ll_random.setOnClickListener(this);
        ll_soul.setOnClickListener(this);
        ll_fate.setOnClickListener(this);
        ll_love.setOnClickListener(this);

        for (int i = 0; i < 100; i++) {
            mData.add("Star" + i);
        }
        // 数据绑定
        mTagAdapter = new CloudTagAdapter(getActivity(), mData);
        mCloudView.setAdapter(mTagAdapter);
        // 监听点击事件
        mCloudView.setOnTagClickListener(new TagCloudView.OnTagClickListener() {
            @Override
            public void onItemClick(ViewGroup parent, View view, int position) {
                Toast.makeText(getActivity(), "position" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_camera:
                // 扫描
                break;

            case R.id.iv_add:
                // 添加好友
                startActivity(new Intent(getActivity(), AddFriendActivity.class));
                break;

            case R.id.ll_random:
                LogUtils.i("随机匹配点击");
                break;

            case R.id.ll_soul:
                LogUtils.i("灵魂匹配点击");
                break;

            case R.id.ll_fate:
                LogUtils.i("缘分匹配点击");
                break;

            case R.id.ll_love:
                LogUtils.i("恋爱匹配点击");
                break;
        }
    }
}